/*
Copyright 2011 Dietmar Wieser, Norbert Lanzanasto, Margit Mutschlechner.
Distributed under the terms of the GNU Lesser General Public License (LGPL).

This file is part of Interactive Museum Guide.

Interactive Museum Guide is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Interactive Museum Guide is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with Interactive Museum Guide.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.wattsa.persistence;

import android.app.Activity;
import android.content.SharedPreferences;

/**
 * This class stores and retrieves persistent data.
 * 
 * @author Margit Mutschlechner
 * */
public class Settings {
	/** the instance of this class -> singleton pattern */
	public static Settings INSTANCE;
	/** the underlaying activity */
	private Activity start = null;
	
	private int spiellaenge;
	private boolean vierVoraus;
	private boolean bei4gehenGibts2;
	private boolean gestrichen4hinten;
	private int spielAusAb;
	private boolean verliererBekommtPunkt;

	/**
	 * this method instantiates the INSTANCE variable.
	 * 
	 * @param start
	 *            the activity
	 * */
	public static void initInstance(Activity start) {
		INSTANCE = new Settings();
		INSTANCE.initSettings(start);
	}

	/**
	 * This method initializes the settings.
	 * 
	 * @param start
	 *            the activity
	 * */
	private void initSettings(Activity start) {
		this.start = start;
		SharedPreferences settings = start.getPreferences(0);
		this.spiellaenge = settings.getInt("spiellaenge", 18);
		this.vierVoraus = settings.getBoolean("vierVoraus", true);
		this.bei4gehenGibts2 = settings.getBoolean("bei4gehenGibts2", true);
		this.gestrichen4hinten = settings.getBoolean("gestrichen4hinten", true);
		this.spielAusAb = settings.getInt("spielAusAb", 7);
		this.verliererBekommtPunkt = settings.getBoolean(
				"verliererBekommtPunkt", true);
	}

	public void setSpiellaenge(int spiellaenge) {
		this.spiellaenge = spiellaenge;
		SharedPreferences settings = start.getPreferences(0);
		SharedPreferences.Editor editor = settings.edit();
		editor.putInt("spiellaenge", spiellaenge);
		editor.commit();
	}

	public int getSpiellaenge() {
		return this.spiellaenge;
	}

	public void setVierVoraus(boolean vierVoraus) {
		this.vierVoraus = vierVoraus;
		SharedPreferences settings = start.getPreferences(0);
		SharedPreferences.Editor editor = settings.edit();
		editor.putBoolean("vierVoraus", vierVoraus);
		editor.commit();
	}

	public boolean getVierVoraus() {
		return this.vierVoraus;
	}

	public void setBei4gehenGibts2(boolean bei4gehenGibts2) {
		this.bei4gehenGibts2 = bei4gehenGibts2;
		SharedPreferences settings = start.getPreferences(0);
		SharedPreferences.Editor editor = settings.edit();
		editor.putBoolean("bei4gehenGibts2", bei4gehenGibts2);
		editor.commit();
	}

	public boolean getBei4gehenGibts2() {
		return this.bei4gehenGibts2;
	}

	public void setGestrichen4hinten(boolean gestrichen4hinten) {
		this.gestrichen4hinten = gestrichen4hinten;
		SharedPreferences settings = start.getPreferences(0);
		SharedPreferences.Editor editor = settings.edit();
		editor.putBoolean("gestrichen4hinten", gestrichen4hinten);
		editor.commit();
	}

	public boolean getGestrichen4hinten() {
		return this.gestrichen4hinten;
	}

	public void setSpielAusAb(int spielAusAb) {
		this.spielAusAb = spielAusAb;
		SharedPreferences settings = start.getPreferences(0);
		SharedPreferences.Editor editor = settings.edit();
		editor.putInt("spielAusAb", spielAusAb);
		editor.commit();
	}

	public int getSpielAusAb() {
		return this.spielAusAb;
	}

	public void setVerliererBekommtPunkt(boolean verliererBekommtPunkt) {
		this.verliererBekommtPunkt = verliererBekommtPunkt;
		SharedPreferences settings = start.getPreferences(0);
		SharedPreferences.Editor editor = settings.edit();
		editor.putBoolean("verliererBekommtPunkt", verliererBekommtPunkt);
		editor.commit();
	}

	public boolean getVerliererBekommtPunkt() {
		return this.verliererBekommtPunkt;
	}

}
